package com.zephyr.vchcenter.bpm.decision;

import org.apache.log4j.Logger;

import com.hiaward.bpm.context.ServiceContext;
import com.hiaward.bpm.exception.ParameterException;
import com.hiaward.bpm.exception.RuleException;
import com.hiaward.bpm.exception.ServiceException;
import com.hiaward.bpm.rule.Decision;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.bpm.action.AuditAction;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;

public class JoinResultDecisionHandler extends Decision {
	private final Logger log=Logger.getLogger(JoinResultDecisionHandler.class);
	@Override
	public void exceptionHandle(ServiceContext arg0) {
		

	}
	@Override
	public String make(ServiceContext arg0) throws RuleException,
			ServiceException, ParameterException {
		log.debug("���� JoinResultDecisionHandler进入JoinResultDecisionHandler................................");
		String vchsid=(String)arg0.getInputParameterValue("vchsid");
		IBaseDao dao=(IBaseDao)SpringHelper.getBean("baseDao");
        Voucher voucher=(Voucher)dao.findById("Voucher", vchsid);
        arg0.setOutputParameterValue("vchsid",vchsid);
		//arg0.setOutputParameterValue("idException", idException);
		//arg0.setOutputParameterValue("chkException", chkException);
		String idresult=voucher.getIdresult();
		String chkres=voucher.getChkres().toString();
		log.debug(idresult);
		log.debug(chkres);
		String transition=null;
		if("4".equals(idresult)){
			log.debug("转向验印意外处理");
			transition="to dealIdentifyExp";
		}else{
			if("2".equals(idresult)&&"2".equals(chkres.toString())){
		    	 log.debug("记账���������̡�����������");
		    	 voucher.setTallytype("1");
		    	 transition="to tally";
		     }else{
		    	 voucher.setTallytype("2");
		    	 log.debug("退票������Ʊ��̡�������������");
		    	 transition="to refuse";
		     }
		}
	     dao.saveOrUpdate(voucher);
		return transition;
	}

}
